<template>
    <div class="common-page page-staff-work-orders-type3" v-loading.fullscreen="loading">
        <div class="common-page__head">
            <!-- <comp-paths class="route" :paths="['/staff/work', $route.fullPath]"></comp-paths> -->
            <div class="title">
                <div class="text">{{ $options.title }}</div>
                <el-button type="plain" size="small" icon="el-icon-plus" style="margin: 0 12px 0 0" @click="addOrder()">提交事项</el-button>
            </div>
        </div>
        <comp-orders class="common-page__body" ref="list" type="type3" select link>
            <!-- <template #head="scope">
                <el-button type="plain" size="small" icon="el-icon-refresh" @click="search()">刷新列表</el-button>
            </template> -->
            <template #body="scope">
                <el-button type="primary" size="mini" @click.stop="getOrder(scope.data)">详情</el-button>
            </template>
        </comp-orders>
    </div>
</template>

<script>
    import mixin from "../mixin";
    import { string, int } from "../util";
    export default {
        name: "page-staff-work-orders-type3",
        title: "我提交的",
        nodes: ["/menu/staff-work"],
        childs: [],
        mixins: [mixin],
        data: () => ({
            loading: false,
        }),
        methods: {
            search() {
                if (this.loading) return;
                this.$nextTick(() => this.$refs.list.init());
            },
            addOrder() {
                if (this.loading) return;
                this.$router.push("/staff/work/order/add");
            },
            getOrder(order) {
                if (this.loading) return;
                this.$router.push("/staff/work/order?orderId=" + order.id);
            },
            destroy() {
                if (this.loading) return;
                return true;
            },
            init() {
                if (this.loading) return;
                this.loading = true;
                this.$root.$refs.navbar.init();
                this.plugins.user.call(async () => {
                    let res = await this.plugins.user.init();
                    if (res.code === 0) { }
                    return res;
                }, async () => {
                    if (this.access(this.$route.name)) return { code: 0 };
                    return this.env.xhrErrors.find((error) => error.code === 4);
                }).then((res) => {
                    this.loading = false;
                    this.$root.$refs.navbar.init();
                    if (res.code === 0) {
                        this.search();
                    } else if (res.code === 2) {
                        this.$root.$refs.navbar.login();
                    } else {
                        this.plugins.modal.alert("页面加载失败", res.code + "：" + res.msg, "error").then(() => this.$router.replace("/home"));
                    }
                });
            },
        },
    };
</script>

<style lang="scss">
    .page-staff-work-orders-type3 {
        overflow: hidden;
    }
</style>